package com.bw.entity;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 登录用户身份权限
 *
 * @author hcc
 * @date 2023-03-05 14:47
 */
@ApiModel(description = "登录用户身份权限")
@NoArgsConstructor
@AllArgsConstructor
@Data
public class LoginUser implements UserDetails {

    /**
     * 用户ID
     */
    @ApiModelProperty("用户ID")
    private Long id;

    @ApiModelProperty(hidden = true)
    private String userName;
    @ApiModelProperty(hidden = true)
    private String password;

    /**
     * 部门ID
     */
    @ApiModelProperty("部门ID")
    private Long deptId;

    /**
     * 用户唯一标识
     */
    @ApiModelProperty("用户唯一标识")
    private String token;

    /**
     * 过期时间
     */
    @ApiModelProperty("过期时间")
    private Long expireTime;

    /**
     * 权限列表
     */
    @ApiModelProperty("权限列表")
    private List<SysMenu> permissionList;

    @ApiModelProperty(hidden = true)
    private List<String> roleList;

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    /**
     * Calls the more complex constructor with all boolean arguments set to {@code true}.
     */
    public LoginUser(Long userId,String username, String password,List<String> authorities) {
       this.id = userId;
       this.userName = username;
       this.password = password;
       this.roleList = authorities;
    }

    @ApiModelProperty(hidden = true)
    private Collection<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    /**
     * 账户是否未过期,过期无法验证
     *
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用,禁用的用户不能身份验证
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
